/**
 * @Author 12629
 * @Description：
 */
class Student {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test {

    public static void main(String[] args) {
        String str = "   abcda  bcdef    ";
        //String ret = str.substring(4,6);//[4,6)
        System.out.println(str);
        String ret = str.trim();//去除左右空格 不会去除 中间的空格
        System.out.println(ret);


    }
    public static void main15(String[] args) {
        String str1 = "192\\168\\0\\1";
        //正则表达式
        String[] ret1 = str1.split("\\\\");
        for(String x : ret1) {
            System.out.println(x);
        }
    }
    public static void main14(String[] args) {
        String str1 = "192.168.0.1";
        //正则表达式
        String[] ret1 = str1.split("\\.");
        for(String x : ret1) {
            System.out.println(x);
        }
    }
    public static void main13(String[] args) {
        String str1 = "name=zhangsan&age=10";
        //正则表达式
        String[] ret1 = str1.split("=|&");
        for(String x : ret1) {
            System.out.println(x);
        }
    }

    public static void main11(String[] args) {
        String str1 = "name=zhangsan&age=10";
        String[] ret1 = str1.split("&");
        for(String x : ret1) {
            //x : name=zhangsan    age=10
            String[] ret2 = x.split("=");
            for(String x2 : ret2) {
                System.out.println(x2);
            }
        }
    }

    public static void main10(String[] args) {
        String str1 = "zhangsan&lisi&wangwu&zhaosi";
        //String[] ret = str1.split("&");
        //最多分几组
        String[] ret = str1.split("&",2);
        for(String x : ret) {
            System.out.println(x);
        }
    }

    public static void main9(String[] args) {
        String str1 = "ababcabcdabcde";
        //String ret = str1.replace('l','p');
        //String ret = str1.replaceAll("ab","kkk");
        String ret = str1.replaceFirst("a","8");
        System.out.println(str1);
        System.out.println(ret);
    }

    public static void main8(String[] args) {
        String s = String.format("%d-%d-%d", 2019, 9,14);
        System.out.println(s);
    }

    public static void main7(String[] args) {
        String str1 = "Hello";

        char[] chars = str1.toCharArray();
        for(char ch : chars) {
            System.out.print(ch+" ");
        }

    }
    public static void main6(String[] args) {
        /*String str1 = "hello";
        String str2 = str1.toUpperCase();
        System.out.println(str1);
        System.out.println(str2);*/

        String str1 = "Hello";
        String str2 = str1.toLowerCase();
        System.out.println(str1);
        System.out.println(str2);
    }
    public static void main5(String[] args) {
        String s1 = String.valueOf(1234);
        String s2 = String.valueOf(12.34);
        String s3 = String.valueOf(true);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        //把对象 转化成了 字符串的形式  -》 序列化
        String s4 = String.valueOf(new Student("zhangsan",10));

        System.out.println(s4);

        int data1 = Integer.parseInt("1234");
        double data2 = Double.parseDouble("12.34");
        System.out.println(data1);
        System.out.println(data2);
    }
    public static void main4(String[] args) {
        String str1 = "ababcabc dabc def";
        //int index = str1.indexOf('l');
        //int index = str1.indexOf("bc",2);
        //从后往前的第一个C
        //int index = str1.lastIndexOf('c');
        //从10这个位置开始 往前走 第一个C
        //int index = str1.lastIndexOf('c',10);
        int index = str1.lastIndexOf(' ');
        System.out.println(index);

    }


    public static void main3(String[] args) {
        String str1 = "hello";
        for (int i = 0; i < str1.length(); i++) {
            char ch = str1.charAt(i);
            System.out.println(ch);
        }
    }
    public static void main2(String[] args) {
        String str1 = new String("abcd");

        String str2 = new String("Abcd");

        System.out.println(str1 == str2);

        System.out.println(str1.equals(str2));
        System.out.println(str1.equalsIgnoreCase(str2));

        System.out.println(str1.compareTo(str2));//
        System.out.println(str1.compareToIgnoreCase(str2));//

       /* System.out.println(str1.length());
        System.out.println(str2.length());*/

        System.out.println("=================");
        String str3 = "hello";
        String str4 = "hello";
        System.out.println(str3 == str4);
    }

    public static void main1(String[] args) {
        String str1 = new String("abcd");
        String str2 = "hello";

        char[] chars = {'w','o','r','l','d'};
        String str3 = new String(chars);

        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);

        byte[] bytes = {97,98,99,100};
        String str4 = new String(bytes);
        System.out.println(str4);
    }
}
